import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Solution690 {

    static class Employee {
        public int id;
        public int importance;
        public List<Integer> subordinates;
    }

    public int getImportance(List<Employee> employees, int id) {
        Map<Integer,Employee> map=new HashMap<>();
        for (Employee employee : employees) {
            map.put(employee.id,employee);
        }
        return cal(map,map.get(id));
    }

    int cal(Map<Integer,Employee> map,Employee employee){
        int ans=employee.importance;
        for (Integer subordinate : employee.subordinates) {
            ans=ans+cal(map,map.get(subordinate));
        }
        return ans;
    }

    public static void main(String[] args) {
        Employee e2=new Employee();
        e2.id=2;e2.importance=3;e2.subordinates=new ArrayList<>();
        Employee e3=new Employee();
        e3.id=3;e3.importance=3;e3.subordinates=new ArrayList<>();
        List<Integer> list=new ArrayList<>();
        list.add(2);list.add(3);
        Employee e1=new Employee();
        e1.id=1;e1.importance=5;e1.subordinates=list;
        List<Employee> list1=new ArrayList<>();
        list1.add(e1);list1.add(e2);list1.add(e3);
        System.out.println(new Solution690().getImportance(list1,1));
    }
}
